package controllers.Administrador;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.ComunidadDeVecinosService;
import services.CuotaService;
import services.PagoService;
import controllers.AbstractController;
import domain.ComunidadDeVecinos;
import domain.Cuota;
import domain.Pago;

@Controller
@RequestMapping("/dashboard/administrator")
public class DashboardAdministratorController extends AbstractController {
	@Autowired
	private PagoService pagoService;
	@Autowired
	private CuotaService cuotaService;
	@Autowired
	private ComunidadDeVecinosService comunidadDeVecinosService;

	public DashboardAdministratorController() {
		super();
	}

	// Listing methods
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ModelAndView list(@RequestParam int comunidadId) {
		ModelAndView result;

		Collection<Cuota> cuotas;
		Collection<Pago> pagos;
		Double fondo;
		ComunidadDeVecinos comunidadDeVecinos;

		comunidadDeVecinos = comunidadDeVecinosService.findOne(comunidadId);
		cuotas = cuotaService.findCuotasByComunidadDeVecinosAdministrador(comunidadId);
		pagos = pagoService.findPagosByComunidadDeVecinos(comunidadId);

		fondo = comunidadDeVecinos.getFondo();

		result = new ModelAndView("dashboard/list");
		result.addObject("requestURI", "dashboard/administrator/list.do");
		result.addObject("cuotas", cuotas);
		result.addObject("pagos", pagos);
		result.addObject("fondo", fondo);
		result.addObject("backURI", "/welcome/index.do");
		return result;
	}

}
